package com.pda.xinma.presenter;

import com.pda.xinma.bean.BackInfoBean;
import com.pda.xinma.contract.EmptyBarrelContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class EmptyBarrelPresenter extends BasePresenter<EmptyBarrelContract .View> implements EmptyBarrelContract.Presenter{

    @Override
    public void emptyContainerIn(String container, String rollerId) {
        NetUtils.geApi().emptyContainerIn(container, rollerId)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<BackInfoBean>>() {
                    @Override
                    public void accept(BaseAppEntity<BackInfoBean> backInfoBeanBaseAppEntity) throws Exception {
                        getView().onSuccess();
                        getView().showMessage(backInfoBeanBaseAppEntity.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void emptyContainerOut(String number, String rollerId) {
        NetUtils.geApi().emptyContainerOut(number, rollerId)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<BackInfoBean>>() {
                    @Override
                    public void accept(BaseAppEntity<BackInfoBean> backInfoBeanBaseAppEntity) throws Exception {
                        getView().onSuccess();
                        getView().showMessage(backInfoBeanBaseAppEntity.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
